// Buddy.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Buddy.h"
#include <ShellAPI.h>
#include "BuddyDlg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CAppModule _Module;



int APIENTRY WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance,
					  LPSTR lpCmdLine, int nCmdShow )
{
	
	HRESULT hRes = ::CoInitialize(NULL);
	// If you are running on NT 4.0 or higher you can use the following call instead to 
	// make the EXE free threaded. This means that calls come in on a random RPC thread.
	//  HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));
	
    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
    ::DefWindowProc(NULL, 0, 0, 0L);
	
    AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls

	_Module.Init ( NULL, hInstance );
	
	
	CBuddyDlg wndMain;
//	MSG msg;
	CMessageLoop msgLoop;
	_Module.AddMessageLoop(&msgLoop);
    // Create the main window
	
    if ( NULL == wndMain.CreateEx() )
	{		
        return 1;       // Window creation failed
	}

    // Show the window
    wndMain.ShowWindow ( nCmdShow );
    wndMain.UpdateWindow();

	int ret = msgLoop.Run();
	
    // Standard Win32 message loop
//     while ( GetMessage ( &msg, NULL, 0, 0 ) > 0 )
// 	{
//         TranslateMessage ( &msg );
//         DispatchMessage ( &msg );
// 	}
//     return msg.wParam;

    _Module.RemoveMessageLoop();
	_Module.Term();

	::CoUninitialize();

	return ret ;
}

